﻿using JESAI.Application.Abstractions.Dtos;
using JESAI.Application.Abstractions.Sys;
using JESAI.Application.Abstractions.Sys.Dtos;
using JESAI.Framework.Filters;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;

namespace JESAI.Platform.WebApi.Controllers.Sys
{
    [ApiController]
    [Route("api/v1/[controller]/[action]")]
    [Authorize("permission")]
    [IgnoreResultHandlerAttribute]
    public class OnlineFormController : ControllerBase
    {
        private readonly IOnlineFormService _onlineFormService;

        public OnlineFormController(IOnlineFormService onlineFormService)
        {
            _onlineFormService = onlineFormService;
        }

        [HttpPost]
        public async Task<BaseOutput> Save([FromBody] JObject formData)
        {
            await _onlineFormService.Save(formData);
            return new BaseOutput();
        }

        [HttpGet]
        public async Task<BaseOutput> GetData( string formId,  string businessKey)
        {
            string jsonString = await _onlineFormService.GetData(formId, businessKey);
            return new BaseOutput<string>(){Data = jsonString};
        }
    }
}
